﻿// See https://aka.ms/new-console-template for more information
using ConsoleApp1;

Console.WriteLine("Hello, World!");

string xml = @" <xml>
                  <ToUserName><![CDATA[toUser]]></ToUserName>
                  <FromUserName><![CDATA[fromUser]]></FromUserName>
                  <CreateTime>12345678</CreateTime>
                  <MsgType><![CDATA[video]]></MsgType>
                  <Video>
                    <MediaId><![CDATA[media_id]]></MediaId>
                    <Title><![CDATA[title]]></Title>
                    <Description><![CDATA[description]]></Description>
                  </Video>
                </xml>";

//微信xml字符串转实体
var msg = WeChatXmlHelper.Parse<WxMessage>(xml);
if (msg != null)
{

    Console.WriteLine(  $"收到消息：{System.Text.Json.JsonSerializer.Serialize(msg)}");

    var reply = new WxMessage
    {
        ToUserName = msg.FromUserName,
        FromUserName = msg.ToUserName,
        CreateTime = msg.CreateTime,
        MsgType = msg.MsgType,
        Video = msg.Video
    };

    //微信实体转xml字符串
    string replyXml = WeChatXmlHelper.ToXml(reply);
    Console.WriteLine(replyXml);
}
